package com.yang.guliproduct.service.impl;

import com.yang.guliproduct.entity.PmsBrand;
import com.yang.guliproduct.entity.PmsCategory;
import com.yang.guliproduct.entity.PmsCategoryBrandRelation;
import com.yang.guliproduct.mapper.PmsCategoryBrandRelationMapper;
import com.yang.guliproduct.service.PmsCategoryBrandRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotBlank;

/**
 * <p>
 * 品牌分类关联 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Service
public class PmsCategoryBrandRelationServiceImpl extends ServiceImpl<PmsCategoryBrandRelationMapper, PmsCategoryBrandRelation> implements PmsCategoryBrandRelationService {

    @Autowired
    private PmsCategoryServiceImpl pmsCategoryService;
    @Autowired
    private  PmsBrandServiceImpl pmsBrandService;

    @Override
    public int addCategoryBrand(PmsCategoryBrandRelation pmsCategoryBrandRelation) {
        Long brandId = pmsCategoryBrandRelation.getBrandId();
        Long catelogId = pmsCategoryBrandRelation.getCatelogId();
        PmsBrand Brand = pmsBrandService.getById(brandId);
        PmsCategory category = pmsCategoryService.getById(catelogId);
        String brandName = Brand.getName();
        String categoryName = category.getName();
        pmsCategoryBrandRelation.setBrandName(brandName);
        pmsCategoryBrandRelation.setCatelogName(categoryName);
        int insert = baseMapper.insert(pmsCategoryBrandRelation);
        return insert;
    }
}
